package com.yc.cinema.mapper;

import com.yc.cinema.bean.Cinema;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

public interface CinemaMapper {

    @Select("select * from cinema")
    List<Map<String, Object>> selectAll();

    @Select("select * from cinema")
    List<Cinema> selectAll2();

    @Select("select * from cinema where name = #{name} and gps = #{gps}")
    @Results( // ==> resultMap 标签
            id = "rm1",
            value = {@Result(column = "id", property = "id", id = true),
                    @Result(column = "name", property = "name"),
                    @Result(column = "id", property = "halls",
                            many = @Many(select = "com.yc.cinema.mapper.HallMapper.selectHalls",
                                    fetchType = FetchType.LAZY))
            }
    )
    Cinema selectByNameAndGps(Cinema c);

    // XX 提交了查询方法
    @Select("select * from cinema where id = #{id}")
    @ResultMap("rm1")
    Cinema selectById(Integer id);

    int update(Cinema cinema);

    @Insert("insert into cinema values(default, #{name}, #{address}, #{gps}, #{img})")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    int insert(Cinema cinema);

    int delete(Integer id);

    int delete(Cinema cinema);

}
